package com.cykj.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @data 2024/8/9 17:46
 * 做登录的拦截器
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        /**
         * 1.获取请求头里面的card_token，拿到的说明以登录那就放行，拿不到就拦截
         * 2.考虑时间问题
         */
        //String token = request.getHeader("ecard_token");
        //System.out.println("进入拦截器");
        //System.out.println(token);
        //if (token == null || token.equals("")){
        //    ResponseDto dto = new ResponseDto(403,"token不存在，请重新登录",null);
        //    response.getWriter().write(JSON.toJSONString(dto));
        //    return false;
        //}
        //
        ////3.判断token是否过期
        //try {
        //    Claims claims = JWTUtils.parseJWT(token);
        //    System.err.println(claims);
        //}catch (Exception e){
        //    ResponseDto dto = new ResponseDto(403,"登录已经过期，请重新登录",null);
        //    response.getWriter().write(JSON.toJSONString(dto));
        //    return false;
        //}
        return true;

    }
}
